package com.lin.blog.service;

import com.lin.blog.mapper.BlogInfoMapper;
import com.lin.blog.mapper.UserInfoMapper;
import com.lin.blog.model.BlogInfo;
import com.lin.blog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;
    //根据用户姓名，查询博客信息
    public UserInfo selectUserInfoByName(String userName) {
       return userInfoMapper.selectByName(userName);
    }

    //根据id查询博客信息
    public UserInfo selectUserInfoById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    //
    public UserInfo selectAuthorInfoByBlogId(Integer blogId) {
        //1.根据博客id,获取作者id
        BlogInfo blogInfo=blogInfoMapper.selectById(blogId);
        //2.根据作者id，获取作者信息
        if(blogInfo==null||blogInfo.getUserId()==null){
            return null;
        }
        UserInfo userInfo=userInfoMapper.selectById(blogInfo.getUserId());
        return userInfo;
    }
}
